/*
 *------------------------------------------------------------------------------
 * @File      :    extdrv_usr.h
 * @Date      :    2021-3-20
 * @Author    :    lomboswer <lomboswer@lombotech.com>
 * @Brief     :    Media Interface for MDP(Media Development Platform).
 *
 * Copyright (C) 2020-2021, LomboTech Co.Ltd. All rights reserved.
 *------------------------------------------------------------------------------
 */

#ifndef __EXTDRV_USR_H__
#define __EXTDRV_USR_H__

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#if defined(__EOS__)
#include "ei_posix.h"
#else
#include <sys/ioctl.h>
#endif
#include "ei_comm_camera.h"
#include <pthread.h>
#include <fcntl.h>

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */

extern EI_S32 VISS_SetPinState(VISS_DEV dev, CAMERA_POWER_ACT_S *pAct, EI_U32 u32Cnt);
EI_S32 VISS_ExtDevRegCallBack(VISS_DEV VissDev, EXT_INFO_S *pstExtInfo);
extern EI_S32 VISS_ExtDevUnRegCallBack(VISS_DEV VissDev);

struct ext_list_head {
    struct ext_list_head *next, *prev;
};

static inline int ext_list_empty(struct ext_list_head *head)
{
    return head->next == head;
}

static inline void __ext_list_del(struct ext_list_head *prev, struct ext_list_head *next)
{
    next->prev = prev;
    prev->next = next;
}

static inline void ext_list_del(struct ext_list_head *entry)
{
    __ext_list_del(entry->prev, entry->next);
}

#define EXT_INIT_LIST_HEAD(ptr) \
do {                        \
    (ptr)->next = (ptr);    \
    (ptr)->prev = (ptr);    \
} while (0)

static inline void __ext_list_add(struct ext_list_head *_new, struct ext_list_head *prev,
    struct ext_list_head *next)
{
    next->prev = _new;
    _new->next = next;
    _new->prev = prev;
    prev->next = _new;
}


static inline void ext_list_add(struct ext_list_head *new, struct ext_list_head *head)
{
	__ext_list_add(new, head, head->next);
}

static inline void ext_list_add_tail(struct ext_list_head *new, struct ext_list_head *head)
{
	__ext_list_add(new, head->prev, head);
}

#define ext_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

#define ext_container_of(ptr, type, member) ( { \
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - ext_offsetof(type,member) ); } )

#define extprintf(fmt, args...)\
do{ \
    printf("%s %d "fmt, __func__, __LINE__, ##args);\
} while(0)


#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /*__cplusplus */

#endif /*__EI_COMM_CAMERA_H__ */
